 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Weapons;

namespace MyApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                textBox1.Enabled = true;
            }
            else if(!checkBox1.Checked)textBox1.Enabled = false;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Enabled = false;
            textBox2.Enabled = false;
            textBox3.Enabled = false;
            textBox1.Text = "0";
            textBox2.Text = "0";
            textBox3.Text = "0";
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox2.Checked)
            {
                textBox2.Enabled = true;
            }
            else if (!checkBox2.Checked) textBox2.Enabled = false;
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox3.Checked)
            {
                textBox3.Enabled = true;
            }
            else if (!checkBox3.Checked) textBox3.Enabled = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            List<AbstractWeapon> productList = new List<AbstractWeapon>();
            int cost = 0;
            int ak = 0;
            int knife = 0;
            int grenade = 0;
            string _ak = textBox1.Text;
            string _knife = textBox2.Text;
            string _grenade = textBox3.Text;
            if (checkBox1.Checked)
            {
                ak = Math.Abs(int.Parse(_ak));
            }
            if (checkBox2.Checked)
            {
                knife = Math.Abs(int.Parse(_knife));
            }
            if (checkBox3.Checked)
            {
                grenade = Math.Abs(int.Parse(grenade));
            }
            Creator[] creators = new Creator[3];
            creators[0] = new ak47Creator;
            creators[1] = new knifeCreator();
            creators[2] = new grenadeCreator();

            foreach (Creator cr in creators)
            {
                if (cr is ak47Creator)
                    productList.Add(cr.FactoryMethod("Автомат АК-47", ak));
                if (cr is knifeCreator)
                    productList.Add(cr.FactoryMethod("Катана", knife));
                if (cr is grenadeCreator)
                    productList.Add(cr.FactoryMethod("РГД", grenade));
            }
            foreach (AbstractWeapon pr in productList)
            {
                cost += pr.cost;
            }
            textBox4.Text = cost.ToString()+" Рублей";
        }
    }
}
